#include <display.h>
#include <string.h>
#include <sys_call.h>

int shm_test(void)
{
	char *str = "Hello, shared memory! This is a test.\n";
	int shmid, pid;
	char *buf;

	shmid = sys_shm_create();

	pid = sys_fork();
	if(pid == 0) { /* child */
	/* Generally, father will execute first, so don't block here.*/
	//	sys_alarm(0);

		buf = sys_shm_attach(shmid);
		printf("child: %s", buf);

		sys_exit(0);
	}

	buf = sys_shm_attach(shmid);
	if((int)buf == -1)
		return -1;
	strcpy(buf, str);
	printf("father: %s", buf);
	sys_wake_up(pid);
	sys_alarm(100);
	sys_shm_remove(shmid);
	return 0;
}

int _start(int argc, char **argv)
{
	printf("Begin shared memory test.\n");
	shm_test();
	/* We should call sys_exit() here explicitly. */
	sys_exit(0);
}
